var fs = require('fs');
var httpRequest = require('request');
var md5 = require('md5-node');

var redis = require('redis');
const bluebird = require('bluebird');

var client = redis.createClient(6379,'localhost');

var mdvv = md5("connect one socket.(socket.id=q3uOxqvWoVzYtmtIAAAQ)");
console.log("md5:"+mdvv);

//"38_tDsJvjEgGhq3Pf6QZApnv9Y63DHe3QxqcNY56q6HUmbFyH7buzUAsBfsmKwJ4yVIEg_ByvLvVJdCO1UeK8bWf2ktXYFLdlYAQCZ6SpTpT_2qKfQE_EFePjTHbvbemVcK8zBm5B_RYaMN4XG_XMHcAHAPEZ"

            httpRequest({
                url: 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=38_Yl3jPC7OtBBrflPHYrOniOBpK6tokSIEH24ryc8EGituh-bl2M9M1XkEYH2bH6v13ELPxGhf_fxIk720FEXEYofNdn3Z6tNVxNt8arD3StfYsFcWQluzqhHZuck98Vdbf5DUGkTirSroUnKJTRVgAEAYWA',
                method: "POST",
                json: true,
                encoding: null,
                headers: {
                    //"content-type": "application/octet-stream",
                },
                body:{
                       'scene' :'7862d4b703c1a136ff9f69a9a94a7075',
                       'is_hyaline' : true,
                       'page' : 'pages/ottShare/ottShare',
                       'width' : 350,
                }
            }, function(error, response, body) {
                if (!error && response.statusCode == 200) {
                    console.log(body.length);
                    //http://wx.ndmooc.com/files/fontdata/   /var/data/note/files/fontdata/
                    fs.writeFile('/var/data/note/files/fontdata/xxo.png', body,(err)=>{
                        console.log(err);
                    });
                    console.log('ok');
                }
            });
 

/*
httpRequest({
        url: 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token=38_tDsJvjEgGhq3Pf6QZApnv9Y63DHe3QxqcNY56q6HUmbFyH7buzUAsBfsmKwJ4yVIEg_ByvLvVJdCO1UeK8bWf2ktXYFLdlYAQCZ6SpTpT_2qKfQE_EFePjTHbvbemVcK8zBm5B_RYaMN4XG_XMHcAHAPEZ',
        method: "POST",
        json: true,
        headers: {
            "content-type": "application/json",
        },
        body:{'content': "没吃过好东西玩意儿，那现在怎么办"}
    }, function(error, response, body) {
        if (!error && response.statusCode == 200) {
            console.log(body.errcode == 87014) // 请求成功的处理逻辑
        }
    });

/*
	client.send_command('ltrim',["fake-channel-name_6_2_1_commentList", 0,-1], function(err, data) {
        console.log(data);
        
 	});

	client.send_command('lrange',["fake-channel-name_6_2_1_commentList", 0,-1], function(err, data) {
        console.log('lrange:')
        console.log(data);
        
    //    data.forEach(function (oneV, i) {
 	    //    console.log(oneV);          //OK 
    //    })
 	});

 httpRequest('https://api.weixin.qq.com/sns/jscode2session?appid=wx8e23853fb3ef2cbc&secret=03e35a38772e13f04c439f009cc46384&js_code=0916Nc000wRcrK1D6C300R830z26Nc0q&grant_type=authorization_code',
    function (error, response, body) {
        if(!error && response.statusCode == 200){
            var requestJson = JSON.parse(body);
            if(requestJson.hasOwnProperty('errcode')){
                console.log("ChinaOKCHinaOk"+requestJson.errcode);
            }else{
                console.log("no ok no ok")
            }
        }
    }
);
*/

/*
client.set('fake-channel-name_writeStream1',"1");
client.set('fake-channel-name_writeStream2',"2");
client.set('fake-channel-name_writeStream3',JSON.stringify('{avatar:"",nickname:"",gender:"",signature:"",role:"",roomId:"",lastSign:""}'));
//client.incr("fake-channel-name_6_2_1_visitNum");
client.mget(["758da4eed5cb8a960ae1f407d10a2a92",'7862d4b703c1a136ff9f69a9a94a7075'], function(err,data){
    console.log("mget:");
    console.log(data);
});

client.expire('xxoo', 60*60*60*7);

/*
client.send_command('append',['xxoo', "seven❤\r\n"]);

client.get('fake-channel-name_writeStream',function(err,val){
    console.log("xxoo:");
    console.log(val);
});
client.sadd('fake-channel-name','ott2', function(err,data) {
    console.log("sadd:");
    console.log(err)
    console.log(data)

    client.smembers('fake-channel-name', function(err,data) {
         console.log("smember:")
         console.log(err);            // [object Array]
         console.log(data);                 // 获取set中的成员, ['redis,mysql]
    })
});
 	client.send_command('lpush',['mylist', 'seven❤'], function(err, data) {
        console.log("mylist have num:"+data);
 	});



 	client.send_command('lrange',["mylist", 0,-1], function(err, data) {
        //console.log(data);
        
        data.forEach(function (oneV, i) {
 	    //    console.log(oneV);          //OK 
        })
 	});

*/
console.log("OK");
